//
//  PositionTableCell.m
//  Estate
//
//  Created by heyong on 16/6/21.
//  Copyright © 2016年 ttsx. All rights reserved.
//
#define SPACING 10
#define TIT_WIDTH 90
#define TEXT_WIDTH  150
#import "PositionTableCell.h"
#import "OrientationViewController.h"

@implementation PositionTableCell


-(UILabel *)title{
    if(_title==nil){
//        _title = [[UILabel alloc] initWithFrame:CGRECTS(8, 2, TIT_WIDTH, 40)];
        
        _title = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, TIT_WIDTH, 40)];
    }
    return _title;
}

//设置位置标题
- (void)setBtnStr:(NSString *)btnStr{
    _btnStr=btnStr;
    CGSize titleSize = [_btnStr sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:self.wzBtn.titleLabel.font.fontName size:self.wzBtn.titleLabel.font.pointSize]}];
    //设置title 和image位置
    CGFloat imageWidth = self.wzBtn.imageView.bounds.size.width;
    self.wzBtn.imageEdgeInsets = UIEdgeInsetsMake(0, titleSize.width+40, 0, -titleSize.width);
    self.wzBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
    
    [self.wzBtn setTitle:_btnStr forState:UIControlStateNormal];
    titleSize.width += 100;
    self.wzBtn.frame=CGRECTS(20+TIT_WIDTH, 2, kScreen_Width-20-TIT_WIDTH-15,40);
}

/**位置btn*/
-(UIButton *)wzBtn{
    if(!_wzBtn){
        _wzBtn=[[UIButton alloc]init];
    }
    return _wzBtn;
}

-(void)setLeft:(CGFloat)left{
    self.title.frame=CGRectMake(left, 2, TIT_WIDTH, 40);
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        self.title.text=@"位   置:";
        self.title.font=[UIFont systemFontOfSize:16.*BIZ];
        self.title.textColor=UIColorFromRGB(0x797979);
        [self.contentView addSubview:self.title];
        
        //添加选择按钮
        [self.contentView addSubview:self.wzBtn];
        //自适应btn长度
        CGSize titleSize = [_btnStr sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:self.wzBtn.titleLabel.font.fontName size:self.wzBtn.titleLabel.font.pointSize]}];
        
        titleSize.height = 44;
        titleSize.width += 100;

        UIImage *bImage=[UIImage imageNamed:@"localize"];
        [self.wzBtn setImage:bImage forState:UIControlStateNormal];

        [_wzBtn addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];
        [self.wzBtn setTitleColor:UIColorFromRGB(0X787878) forState:UIControlStateNormal];
        self.wzBtn.titleLabel.font=[UIFont systemFontOfSize:16*BIZ];
        self.wzBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

    }
    return self;
}


- (void)clickAction
{
    if (self.isEdit) {
        if(self.cliclWzBlock){
            self.cliclWzBlock();
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}
//设置分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);
    //    //上分割线，
    //    CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor); CGContextStrokeRect(context, CGRectMake(0, -1, rect.size.width , 1));
    //下分割线
    CGContextSetStrokeColorWithColor(context,[UIColor colorWithRed:0.89 green:0.89 blue:0.90 alpha:1.00].CGColor);
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
